package com.qef.com.mmovie.utils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.orhanobut.logger.Logger;

import java.util.List;

/**
 * Json处理类
 * Created by guangjiego on 2016/3/1.
 */
public class GsonUtils {
    //    public static Gson gson = new Gson();
    public static Gson gson = new GsonBuilder().serializeNulls().create();

    public static Object jsonToBean(String result, Class clazz) {
        try {
            gson.fromJson(result, clazz);
        } catch (Exception e) {
            Logger.i("xxx=" + result);
        }

        return  gson.fromJson(result, clazz);
    }

    /**
     * json直接转换成字符串
     *
     * @param response
     */
    public static String toJson(String response) {
//        List<Map<String, String>> list = gson.fromJson(response,
//                new TypeToken<List<Map<String, String>>>() {
//                }.getType());
//        return list.get(0).get("Token");
        return null;
    }

    public static String beanToJson(Object obj) {
        return gson.toJson(obj);
    }

    //将集合转换成json
    public static String listToJson(List<String> histories) {
        return gson.toJson(histories);
    }
}
